import {createStore} from 'redux';
import rootReducer from './reducers';

const store = createStore(rootReducer);

//中间原理 核心 就是 狸猫换太子
const dispatch = store.dispatch;

//中间件 ---> 夹心
/*store.dispatch = function(action){
  console.log('prev state',store.getState());
  dispatch(action);
  console.log('next state', store.getState());
  return action;
}*/

//中间件要实现支持异步
store.dispatch = function(action){
  setTimeout(() => {
    dispatch(action);
  }, 3000);
  return action;
}

export default store;
